<template>
	<div class="index">
		<span id="1" style="display: none;">
			{{current.userId}}
		</span>
		<div id="updatep">
			<van-form @submit="onSubmit">
			  <van-field
			    v-model="upassword"
			    name="新密码"
			    label="新密码"
			    placeholder="新密码"
			    :rules="[{ required: true, message: '请填写新密码' },{ pattern: /\d{6}/,message: '密码至少为6位',trigger: 'onBlur'}]"
			  />
			  <van-field
			    v-model="confirmpassword"
			    type="password"
			    name="确认密码"
			    label="确认密码"
			    placeholder="确认密码"
			    :rules="[{ required: true, message: '请确认密码' },{ pattern: /\d{6}/,message: '密码至少为6位',trigger: 'onBlur'}]"
			  />
			  <div style="margin: 16px;">
			    <van-button round block type="info" native-type="submit">提交</van-button>
			  </div>
			</van-form>
		</div>
	</div>
</template>

<script>
	import store from '../../common/store.js'
	import { Toast } from 'vant';
	export default {
		data() {
			return {
			upassword:'',
			confirmpassword:'',
			userId:'',
			currentUser:{},
			openId:''
			}
			
		},
		methods: {
			// logout: () => {
			// 	store.commit('loginOut')
			// },
			onSubmit:function(values) {
				if(this.$data.upassword != this.$data.confirmpassword){
					Toast("两次输入不一致")
				}else if(this.$data.upassword == this.$data.confirmpassword){
					this.http
					    .put({
							url:'/system/student/password',
							param:{
								userId: this.$data.userId,
								password: this.$data.upassword,
								openId: this.$data.openId
							}
						}).then((data) => {
                             Toast("修改成功")
							 store.commit('loginOut')
                        })
				}
			}
			
	
		},
		created: function() {
			
		},
		mounted() {
			this.$data.openId = this.$store.state.openId
			this.$data.userId = this.$data.currentUser.user.userId
			console.log(this.$data.currentUser)
			// window.addEventListener("click", this.search);
		},
		computed: {
			current: function() {
				this.$data.currentUser = store.state.currentUser
				return store.state.currentUser
			},
		},
		
	
	}
</script>

<style scoped>
	.index{
		background-color: #f7f7f7;
		height: 100vh;
	}
	#updatep{
		
		height: 50vh;
		position: relative;
		top: 200px;
	}
</style>
